home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Development Tools & Languages / DTSCPlusLibrary / Sources / Window.cp < prev    next >
Encoding:
Text File  |  1993-01-14  |  4.8 KB  |  201 lines  |  [TEXT/MPS ]

  1. /* _________________________________________________________________________________________________________ //
  2.   Copyright © 1992-93 Apple Computer, Inc. All rights reserved.
  3.   Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
  4.   Date: 11/7/92
  5.   Revision comments are at the end of this file.
  6.   ---
  7.   TWindow is a Window wrapper class that handles most of the basic window functionality.
  8.   Window.cp contains the TWindow member functions.
  9.   _________________________________________________________________________________________________________ */
  10.  
  11. #ifndef _WINDOW_
  12. #include "Window.h"
  13. #endif 
  14.  
  15.  
  16. // _________________________________________________________________________________________________________ //
  17. // TWindow class member function implementations.
  18. // CONSTRUCTORS AND DESTRUCTORS
  19. #pragma segment Window
  20. TWindow::TWindow()
  21. {
  22.     this->Initialize();                            // initialize fields to known values    
  23.  
  24.     // Create Window.
  25.     TEnvironment myEnvironment;                    // check out our environment if Color QD is present
  26.  
  27.     if (myEnvironment.HasColorQD())
  28.     {
  29.         fWindow = ::NewCWindow(NULL, &fRect, fWindowTitle, true, noGrowDocProc, (WindowPtr) - 1L, true, 0L);
  30.         fColorWindow = true;
  31.     }
  32.     else
  33.         fWindow = ::NewWindow(NULL, &fRect, fWindowTitle, true, noGrowDocProc, (WindowPtr) - 1L, true, 0L);
  34.  
  35.     ASSERT(fWindow != NULL, "\pProblems with TWindow::TWindow, NewWindow");
  36.     fWindowRecord = (WindowPeek)fWindow;        // get ptr to the real window record        
  37. }
  38.  
  39.  
  40. #pragma segment Window
  41. TWindow::TWindow(short windowID)
  42. // Create window based on resource ID.
  43. {
  44.     fColorWindow = false;                        // can't assume anything…
  45.  
  46.     // Create Window.
  47.     TEnvironment myEnvironment;                    // check out our environment if Color QD is present
  48.  
  49.     if (myEnvironment.HasColorQD())
  50.     {
  51.         fWindow = ::GetNewCWindow(windowID, NULL, (WindowPtr) - 1);
  52.         fColorWindow = true;
  53.     }
  54.     else
  55.         fWindow = ::GetNewCWindow(windowID, NULL, (WindowPtr) - 1);
  56.     ASSERT(fWindow != NULL, "\pProblems with TWindow::TWindow(ResID), GetNewWindow");
  57.  
  58.     fWindowRecord = (WindowPeek)fWindow;        // get ptr to the real window record        
  59. }
  60.  
  61.  
  62. #pragma segment Window
  63. TWindow::~TWindow()
  64. // Default destructor -- get rid of the window memory allocations.
  65. {
  66.     ::DisposeWindow(fWindow);                    // dispose our WindowPtr
  67. }
  68.  
  69.  
  70. #pragma segment Window
  71. void TWindow::Initialize()
  72. // Initialize the window to a known state (title, position).
  73. {
  74.     Pstrcpy(fWindowTitle, "\pUntitled");        // set default window title
  75.     fRect.top = TWindow::kTop;                    // set default window rect
  76.     fRect.left = TWindow::kLeft;
  77.     fRect.bottom = TWindow::kBottom;
  78.     fRect.right = TWindow::kRight;
  79.  
  80.     fColorWindow = false;                        // can't assume anything…
  81. }
  82.  
  83.  
  84. // MAIN INTERFACE
  85. #pragma segment Window
  86. void TWindow::Draw()
  87. // Draw is an implementation dependent function, you need to override this one
  88. // and create your own drawing routines.
  89. {
  90. }
  91.  
  92.  
  93. #pragma segment Window
  94. void TWindow::DoClick()
  95. // DoClick is an implementation dependent function, you need to override this one
  96. // and create your own mouse click routines.
  97. {
  98. }
  99.  
  100.  
  101. #pragma segment Window
  102. void TWindow::Show()
  103. // Make window visible.
  104. {
  105.     ::ShowWindow(fWindow);
  106. }
  107.  
  108.  
  109. #pragma segment Window
  110. void TWindow::Hide()
  111. // Make window invisible.
  112. {
  113.     ::HideWindow(fWindow);
  114. }
  115.  
  116.  
  117. // GET/SET FUNCTIONS
  118. #pragma segment Window
  119. WindowPtr TWindow::GetWindowPtr() const
  120. // Get the actual windowPtr record.
  121. {
  122.     return fWindow;
  123. }
  124.  
  125.  
  126. #pragma segment Window
  127. void TWindow::SetTitle(const Str255* title)
  128. // Set window title.
  129. {
  130.     Str255 oldTitle;
  131.  
  132.     // Get old title, if still the same, don't bother changing it (less flicker)
  133.     ::GetWTitle(fWindow, oldTitle);
  134.  
  135.     if (!CompareStr255(&oldTitle, title))
  136.         ::SetWTitle(fWindow, *title);
  137. }
  138.  
  139.  
  140. #pragma segment Window
  141. void TWindow::GetTitle(Str255* result) const
  142. // Get window title.
  143. {
  144.     if (fWindow)                                // we have a valid window?
  145.         ::GetWTitle(fWindow, *result);
  146.     else
  147.         Pstrcpy(*result, "\p");                    // copy in an empty string
  148. }
  149.  
  150.  
  151. #pragma segment Window
  152. Rect TWindow::GetExtent() const
  153. // Get the internal Rect of window.
  154. {
  155.     return fWindow->portRect;
  156. }
  157.  
  158.  
  159. #pragma segment Window
  160. Rect TWindow::GetFrame() const
  161. // Get the frame Rect of window.
  162. {
  163.     Rect frame;
  164.     
  165.     frame.left = -1;
  166.     frame.top = -1;
  167.  
  168.     // Include one pixel for the the frame itself!
  169.     frame.right = fWindow->portRect.right - fWindow->portRect.left + 1;
  170.     frame.bottom = fWindow->portRect.bottom - fWindow->portRect.top + 1;
  171.  
  172.     return frame;
  173. }
  174.  
  175.  
  176. #pragma segment Window
  177. Boolean TWindow::Contains(Point test) const
  178. // Check if point is inside window.
  179. {
  180.     return (::PtInRgn(test, fWindowRecord->contRgn));
  181. }
  182.  
  183.  
  184. #pragma segment Window
  185. Boolean TWindow::IsColorWindow() const
  186. // Return true/false if window is a color grafport based one.
  187. {
  188.     return fColorWindow;
  189. }
  190.  
  191.  
  192. // _________________________________________________________________________________________________________ //
  193.  
  194.  
  195. /*    Change History (most recent last):
  196.   No        Init.    Date        Comment
  197.   1            khs        11/7/92        New file
  198.   2            khs        1/7/93        Cleanup
  199. */
  200.  
  201.